Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
searchParams.get returning "Null" when values are present

I'm trying to grab URL params from a page link to prepopulate a form in an iFrame, but am struggling with the params returning 'null' and need some guidance. So far, the script appears to work by populating the form with "null", however, it is unsuccessfully populating params that have valid values in my URL. The javascript below 'f.src' is scripting provided by my forms service.

(I apologize for the ugly console.logs, but am using those for troubleshooting.)

***UPDATE: With my updated code, per user suggestion, I updated my .get statements to specify the param with a string, but it's still returning 'null'.

try{
        var endpoint = "https://forms.myformsite.com/";
        console.log(endpoint);
        var url_string = "https://my.site.com/landingpage?fname=Jeff&lname=Bezos&email=jeff@amazon.com&company=Amazon&title=Founder"; /*window.location.href;*/
        console.log(url_string);
        var url = new URL(url_string);
        console.log(url_string);
        var fname = url.searchParams.get('fname');
        console.log(fname);
        var lname = url.searchParams.get('lname');
        console.log(lname);
        var email = url.searchParams.get('email');
        console.log(email);
        var company = url.searchParams.get('company');
        console.log(company);
        var title = url.searchParams.get('title');
        console.log(title);
        var formURL = endpoint+"&fname="+fname+"&lname="+lname+"&email="+email+"&company"+company+"&title="+title;
        console.log(formURL);
        var f = document.createElement("iframe");   
        f.src = formURL;
        console.log(f.src);
        f.style.border = "none";
        f.style.height = "878px";
        f.style.width = "90%";
        f.style.transition = "all 0.5s ease";
        var d = document.getElementById("divFormID");
        d.appendChild(f);
        window.addEventListener('message', function() {
            var evntData = event.data;
            if (evntData && evntData.constructor == String) {
                var zf_ifrm_data = evntData.split("|");
                if (zf_ifrm_data.length == 2) {
                    var zf_perma = zf_ifrm_data[0];
                    var zf_ifrm_ht_nw = (parseInt(zf_ifrm_data[1], 10) + 15) + "px";
                    var iframe = document.getElementById("divFormID").getElementsByTagName("iframe")[0];
                    if ((iframe.src).indexOf('formperma') > 0 && (iframe.src).indexOf(zf_perma) > 0) {
                        var prevIframeHeight = iframe.style.height;
                        if (prevIframeHeight != zf_ifrm_ht_nw) {
                            iframe.style.height = zf_ifrm_ht_nw;
                        }
                    }
                }
            }
        }, false);
    } catch (e) {}
})();```


about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For all .get() calls, you're passing in an (undefined) variable instead of a string:

var fname = url.searchParams.get(fname);

This should be:

var fname = url.searchParams.get('fname');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!